{% load static %}
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>学生选课系统-主页</title>
    <link rel="stylesheet" href="{% static  "bootstrap3/css/bootstrap.min.css" %}">
    <link rel="stylesheet" href="{% static "bootstrap3/css/bootstrap-theme.min.css" %}">
    <link rel="stylesheet" href="{% static "css/xsxk.css" %}">
    <style type="text/css">
        .navbar-inverse {
            background-color: #337ab7;
            border-color: #337ab7;
        }
    </style>
    <script src="{% static "bootstrap3/js/jquery-1.11.2.min.js" %}"></script>
    <script src="{% static "bootstrap3/js/bootstrap.min.js" %}"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
                <div class="container">
                    <div class="navbar-header">
                        <a class="navbar-brand " href="#">学生选课系统</a>
                    </div>
                    <div id="navbar" class="navbar-right">
                        <a class="navbar-brand" href="#">当前用户：{{ user.userName }} [{{ userType }}]</a>
                    </div>
                </div>
            </nav>
        </div>
    </div>

    <div class="row" style="padding-top: 45px;">
        <div class="col-md-3">
            <script type="text/javascript">
                function logout() {
                    if (confirm('您确定要退出系统吗？')) {
                        window.location.href = "../login";
                    }
                }
            </script>
            <div class="list-group">
                <a href="#" class="list-group-item active">
                    系统菜单
                </a>
                {% if userType == "管理员" %}
                    <a href="../main/manager_student_info" class="list-group-item">学生信息管理</a>
                    <a href="../main/manager_teacher_info" class="list-group-item">教师信息管理</a>
                    <a href="../main/manager_course_info" class="list-group-item">课程信息管理</a>
                    <a href="javascript:logout()" class="list-group-item">安全退出</a>
                {% endif %}
                {% if userType == "老师" %}
                    <a href="../main/teacher_showCourse" class="list-group-item">查看课程</a>
                    <a href="../main/teacher_showStudent" class="list-group-item">查看学生</a>
                    <a href="../main/teacher_scoreInfo" class="list-group-item">成绩录入</a>
                    <a href="../main/teacher_showInfo" class="list-group-item">个人信息查看</a>
                    <a href="javascript:logout()" class="list-group-item">安全退出</a>
                {% endif %}
                {% if userType == "学生" %}
                    <a href="../main/student_course_list" class="list-group-item">课程信息查看</a>
                    <a href="../main/student_select_course" class="list-group-item">选择课程</a>
                    <a href="../main/student_showScore" class="list-group-item">成绩查询</a>
                    <a href="../main/student_select_showInfo" class="list-group-item">个人信息查看</a>
                    <a href="javascript:logout()" class="list-group-item">安全退出</a>
                {% endif %}
            </div>
        </div>
        <div class="col-md-9">
            <div>
                <ol class="breadcrumb">
                    <li><span class="glyphicon glyphicon-home"></span>&nbsp;
                        <a href="">主页</a></li>
                    <li class="active"></li>
                </ol>
            </div>
         <div>
                <div class="col-md-6">
                    <form action="../student/select_course_search" method="post">

                        <div class="input-group" style="width: 300px">
                            <input type="text" class="form-control" name="content" placeholder="请输入要查询的课程名称...">
                            <span class="input-group-btn">
		        <button class="btn btn-default" type="submit"><span
                        class="glyphicon glyphicon-search"></span>&nbsp;查询</button>
		      </span>
                        </div>
                    </form>
                </div>
            <div class="row">
                <div class="col-md-12">
                    <script type="text/javascript">

                        // 选择课程

                        function selectCourse(){
                            var chk_value=[];
                            $('input[name="s_courseIds"]:checked').each(function(){
                                chk_value.push($(this).val());
                            });
                            if(chk_value.length==0){
                                alert("请选择要课程");
                                return;
                            }
                            var courseIds=chk_value.join(",");
                            //alert(courseIds);
                            if(confirm("您确认要选择这些课程吗？")){
                                $.post("../select",{courseIds:courseIds},
                                    function(result){
                                        //alert(result)
                                        if(result=="success"){
                                            alert("选择成功");
                                            window.location.href="../main/student_select_course";
                                        }else{
                                            alert(result);
                                        }
                                    }
                                );
                            }
                        }

                        // 退选课程
                        function unselectCourse() {
                            var chk_value = [];
                            $('input[name="scIds"]:checked').each(function () {
                                chk_value.push($(this).val());
                            });
                            if (chk_value.length == 0) {
                                alert("请选择要退选的课程");
                                return;
                            }
                            var scIds = chk_value.join(",");
                            if (confirm("您确认要退选这些课程吗？")) {
                                $.post("../delete", {scIds: scIds},
                                    function (result) {
                                        //var result = eval('(' + result + ')');
                                        if (result=="success") {
                                            alert("删除成功");
                                            window.location.href = "../main/student_select_course";
                                        } else {
                                            alert(result);
                                        }
                                    }
                                );
                            }
                        }

                    </script>
                    <div class="panel panel-default">
                        <div class="panel-heading">可选课程</div>
                        <table class="table table-hover  table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>&nbsp;</th>
                                <th>序号</th>
                                <th>课程名称</th>
                                <th>学分</th>
                                <th>授课老师</th>
                            </tr>
                            {% for false_course in false_courses %}
                                <tr>
                                    <td><input type="checkbox" id="select_course" name="s_courseIds"
                                               value="{{ false_course.id }}"/></td>
                                    <td>{{ false_course.id }}</td>
                                    <td>{{ false_course.courseName }}</td>
                                    <td>{{ false_course.credit }}</td>
                                    <td>{{ false_course.teacherId.trueName }}</td>
                                <td><a href="../info/?data_id=course_{{ false_course.id }}">点击查看</a></td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                        <button type="button" id="selectButton" class="btn btn-success" onclick="selectCourse()" style="margin: 5px">选择课程
                        </button>
                    </div>
                    <hr/>
                    <div class="panel panel-default">
                        <div class="panel-heading">已选课程</div>
                        <table class="table table-hover  table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>&nbsp;</th>
                                <th>序号</th>
                                <th>课程名称</th>
                                <th>学分</th>
                                <th>授课老师</th>
                                <th>详情</th>
                            </tr>
                            {% for select_course in select_courses %}
                                <tr>
                                    <td><input type="checkbox" name="scIds" value="{{ select_course.id }}"/></td>
                                    <td>{{ select_course.id }}</td>
                                    <td>{{ select_course.courseName }}</td>
                                    <td>{{ select_course.credit }}</td>
                                    <td>{{ select_course.teacherId.trueName }}</td>
                                    <td><a href="../info/?data_id=course_{{ select_course.id }}">点击查看</a></td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                        <button type="button" class="btn btn-danger" style="margin: 5px" onclick="unselectCourse()">
                            退选课程
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
</body>
</html>